package com.schezhi.link.auth.constant;

/**
 * @Author: JiaLing.Fan
 * @Date: 2022/11/16 14:32
 * @Description:
 */
public enum AuthResultCodeEnum {
    TOKEN_EMPTY("TOKEN_EMPTY", "令牌为空"),
    TOKEN_INVALID("TOKEN_INVALID", "会话信息不存在"),
    TOKEN_MISMATCH("TOKEN_MISMATCH", "令牌不匹配"),
    USER_INSUFFICIENT_PERMISSION("USER_INSUFFICIENT_PERMISSION", "用户权限不足"),
    USER_VERSION_UPGRADE("USER_VERSION_UPGRADE", "用户版本升级");


    private String code;

    private String msg;

    AuthResultCodeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    // 静态方法：判断传入的 code 是否匹配当前枚举
    public static boolean isCodeMatch(String targetCode, AuthResultCodeEnum errorCode) {
        return errorCode.getCode().equals(targetCode);
    }
    // 静态方法：根据 code 查找对应的枚举
    public static AuthResultCodeEnum getByCode(String targetCode) {
        for (AuthResultCodeEnum errorCode : values()) {
            if (errorCode.getCode().equals(targetCode)) {
                return errorCode;
            }
        }
        return null; // 或抛出异常
    }
}
